local hx__honglian = fk.CreateSkill{
    name = "hx__honglian",

    tags = {Skill.Compulsory},
}

fk.MagicDamage = 8
Fk:addDamageNature(fk.MagicDamage, "magic_damage", true)

hx__honglian:addEffect(fk.BeforeHpChanged,{
  can_refresh = function(self, event, target, player, data)
    return player == target and data.damageEvent and data.damageEvent.damageType == fk.MagicDamage
  end,
  on_refresh = function (self, event, target, player, data)
    data.num = data.num - data.shield_lost
    data.shield_lost = 0
    --player.room:broadcastPlaySound("./packages/moepack/audio/card/charm_damage")
    player.room:delay(200)
  end,
})

hx__honglian:addEffect(fk.DamageInflicted,{
    can_trigger = function (self, event, target, player, data)
        return player:hasSkill(hx__honglian.name) and target and target == player 
        and table.find(player:getCardIds("he"),function (c)
            return Fk:getCardById(c).color == Card.Red
        end)
    end,
    on_cost = function (self, event, target, player, data)
        local room = player.room
        if data.from then
          return #room:askToDiscard(player,{ min_num = 1, max_num = 1, skill_name = hx__honglian.name , cancelable = true , include_equip = true , prompt = "#hx__honglian__evoke1::"..data.from.id..":"..data.damage,  pattern = ".|.|heart,diamond",}) > 0
        else
          return #room:askToDiscard(player,{ min_num = 1, max_num = 1, skill_name = hx__honglian.name , cancelable = true , include_equip = true , prompt = "#hx__honglian__evoke2:::"..data.damage,  pattern = ".|.|heart,diamond",}) > 0
        end
    end,
    on_use = function (self, event, target, player, data)
        local room = player.room
        if data.from then
            room:damage{
                to = data.from,
                damage = 1,
                from = player,
                damageType = fk.MagicDamage
            }
        end
        data:preventDamage()
    end,
})

hx__honglian:addEffect(fk.DamageCaused,{
    priority = 1.1,
    can_trigger = function (self, event, target, player, data)
        return player:hasSkill(hx__honglian.name) and target and target == player and data.damage and data.damageType == fk.FireDamage
        and table.find(player:getCardIds("he"),function (c)
            return Fk:getCardById(c).color == Card.Black
        end)
    end,
    on_cost = function (self, event, target, player, data)
        local room = player.room
        return #room:askToDiscard(player,{ min_num = 1, max_num = 1, skill_name = hx__honglian.name , cancelable = true , include_equip = true , prompt = "#hx__honglian__evoke3::"..data.to.id..":"..data.damage,  pattern = ".|.|club,spade",}) > 0
    end,
    on_use = function (self, event, target, player, data)
        local room = player.room
        room:damage{
            to = data.to,
            damage = data.damage,
            from = player,
            damageType = fk.MagicDamage,
        }
    end,
})


return hx__honglian